{include file="public/header" /}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="start_date" id="start_date" placeholder="开始日期" autocomplete="off" class="layui-input" />
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" name="end_date" id="end_date" placeholder="截至日期" autocomplete="off" class="layui-input" />
                    </div>
                    <div class="layui-input-inline">
                        <select name="status" id="status">
                            <option value="">全部</option>
                            <option value="-1">待处理</option>
                            <option value="1">已处理</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="layui-app-form" id="layui-app-form" style="display:none" >
                <div class="layui-form-item" style="margin-top: 20px">
                    <label class="layui-form-label">问题反馈</label>
                    <div class="layui-input-block">
                        <input type="text" id="title" lay-verify="required" style="width: 95%" class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-top: 20px">
                    <label class="layui-form-label">详情描述</label>
                    <div class="layui-input-block">
                        <input type="text" id="content" lay-verify="required" style="width: 95%" class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">处理结果</label>
                    <div class="layui-input-block">
                        <textarea id="remarks" name="remarks" autocomplete="on" style="width: 95%" class="layui-textarea"></textarea>
                        <p>系统建议255字符以内</p>
                    </div>
                </div>
            </form>
            <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
            <script type="text/html" id="table-content-list">
                <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit"><i class="layui-icon">处理</i></a>
                <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete"><i class="layui-icon">删除</i></a>
            </script>
        </div>
    </div>
</div>
<script>
layui.use(['layer', 'table','form','laydate'], function(){
    var $ = layui.$
            ,table = layui.table
            ,laydate = layui.laydate
            ,form = layui.form;
    laydate.render({
        elem: '#start_date'
        , trigger:'click'
    });
    laydate.render({
        elem: '#end_date'
        , trigger:'click'
    });
    table.render({
        elem: '#LAY-app-content-list'
        ,url: "{:url('feedback/getFeedbackList')}"
        , request: {
            pageName: 'page',
            limitName: 'page_size'
        }
        , page: {
            layout: ['limit', 'count', 'prev', 'page', 'next', 'skip']
            ,first: '首页'
            ,last: '尾页'
            ,limit: 10
        }
        , toolbar:true
        , totalRow: true
        , cellMinWidth: 120
        ,cols: [[
            {field: 'id',type: 'checkbox', align: 'center'}
            ,{field: 'id', width: 80, title: 'ID', align:'center'}
            ,{field: 'title', title:'反馈/建议',align:'center'}
            ,{field: 'images', title: "图片", width:240, align:'center', event:'showCoverBigImage', templet: function (d) {
                if(d.images){
                    var image_list = d.images;
                    str = '<div id="layer-photos-cover-'+ d.id +'" class="layer-photos-demo">';
                    $.each(image_list, function(index, item) {
                        str += '<img  layer-src="'+ item +'" src="'+ item +'" style="width:35px;margin-right:5px">';
                    });
                    return str;
                } else {
                    return '';
                }
            }}
            ,{field: 'status', title: "状态", align:'center', templet: function (d) {
                var is_checked = '';
                if (d.status == 1) {
                    is_checked = 'checked';
                }
                return '<input type="checkbox" name="status" switch_status_id="'+ d.id +'" value="'+ d.status +'" lay-skin="switch" lay-text="已处理|未处理" lay-filter="status" '+ is_checked +'>';
            }}
            ,{field: 'create_time', title:'反馈时间',align:'center'}
            ,{field: 'update_time', title:'处理时间',align:'center', templet: function (d) {
                if (d.status) {
                    return d.update_time;
                } else {
                    return '';
                }
            }}
            ,{title: '操作', minWidth: 200, align: 'center', toolbar: '#table-content-list'}
        ]]
        , text: {
            none: '暂无相关数据'
        }
    });
    form.on('submit(LAY-app-contlist-search)', function (data) {
        var field = data.field;
        table.reload('LAY-app-content-list', {
            page: {
                curr: 1
            }
            , where: field
        });
    });
    // 监听工具条
    table.on('tool(LAY-app-content-list)', function(obj){
        var data = obj.data;
        if(obj.event === 'delete'){
            layer.confirm('确定删除该条记录吗？', {title : '温馨提示'}, function(index){
                $.ajax({
                    url:"{:url('feedback/delete')}",
                    type:'post',
                    data:{'id':data.id},
                    success: function(res){
                        if (res.code == 0) {
                            obj.del();
                            layer.msg(res.msg, {icon: 1});
                        } else {
                            layer.msg(res.msg, {icon: 5});
                        }
                    }
                });
            });
        } else if(obj.event === 'edit'){
            $("#title").val(data.title);
            $("#content").val(data.content);
            $("#remarks").val(data.remarks);
            layer.open({
                type:1,
                skin: 'demo-class',
                area:['800px','85%'],
                title: '处理反馈',
                content: $("#layui-app-form"),
                shade: 0,
                btn: ['确定', '取消'],
                yes: function(){
                    var remarks = $('#remarks').val();
                    if (remarks == ''){
                        return layer.msg('处理意见不能为空', {icon: 5});
                    }
                    $.post("{:url('feedback/edit')}", {id:data.id, remarks:remarks, name:name}, function (res) {
                        if (res.code == 0) {
                            layer.msg(res.msg, {icon: 1});
                            table.reload('LAY-app-content-list');
                            $("#layui-app-form")[0].reset();
                            layer.closeAll();
                        } else {
                            layer.msg(res.msg, {icon: 5});
                        }
                    });
                },
                btn2: function(){
                    $("#layui-app-form")[0].reset();
                    layer.closeAll();
                },
                cancel: function(){
                    $("#layui-app-form")[0].reset();
                    layer.closeAll();
                }
            });
        } else if( obj.event == 'showCoverBigImage'){
            layer.photos({
                photos: '#layer-photos-cover-'+ data.id
                , anim: 5
            });
        }
    });

    var $ = layui.$, active = {

    };

    $('.layui-btn.layuiadmin-btn-list').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
});
</script>
{include file="public/footer"}
